<template>
  <div class="order">
    <van-nav-bar :title="titles" left-arrow @click-left="$router.back()" />
    <van-tabs @click="onClick">
      <van-tab v-for="item in orderclass" :key="item.id" :title="item.class_names">
        <div class="recommend" v-if="flag">
          <img
            src="//jp.juancdn.com/jpwebapp_v1/images_v1/shopping/empty-order.png?598b3089-1&sv=449ce9ee"
            alt
          />
          <p>暂无订单</p>
          <a href="/">今日推荐</a>
        </div>
        <div class="ordercreated" v-else>
          <van-cell-group v-for="item in orderlist" :key="item.id">
            <van-cell></van-cell>
            <van-cell class="imgcell">
              <div slot="title">
                <img width="60px" height="60px" :src="item.shop_image" />
                <span class="title">{{item.shop_name}}</span>
                <span class="tuih">7天退货</span>
              </div>
              <span class="price">￥{{(item.shop_price-0).toFixed(2)}}</span>
              <span class="num">X1</span>
            </van-cell>
            <van-cell :title="'实付款￥'+(item.shop_price-0).toFixed(2)" :value="'共1件'"></van-cell>
            <van-cell title="支付方式" class="zffs">
              <div slot="default">
                <img :src="paymethod[0].img" />
                <span class="zfm">{{paymethod[0].zfm}}</span>
                <span class="payway-tips-text">{{paymethod[0].pay_text}}</span>
              </div>
            </van-cell>
          </van-cell-group>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      orderclass: [],
      titles: "全部订单",
      flag: false,
      orderlist: [],
      paymethod: []
    };
  },
  created() {
    this.$http.get("/orderclass").then(res => {
      // console.log(res);
      if (res.data.code === 201) {
        this.orderclass = res.data.data;
      }
    });
    let id = localStorage.getItem("orderid");
    this.$http.get("/order_confirm", { params: { id: id } }).then(res => {
      console.log(res.data.data);
      if (res.data.code === 201) {
        // this.orderlist = res.data.data;
        res.data.data.forEach(v => {
          this.orderlist.push(v);
          // this.orderlist += "";
          // this.price.push(v.shop_price-0)
        });
      }
    });
    this.paymethod.push(JSON.parse(localStorage.getItem("paymethod")));
    // this.paymethod +=''
    console.log(this.paymethod);
  },
  computed: {
    ...mapState(["shopID", "shopCount", "shopSelect"])
  },
  methods: {
    onClick(name, title) {
      for (let i = 0; i < this.orderclass.length; i++) {
        if (name < i) {
          this.titles = title;
        }
      }
    }
  }
};
</script>
<style lang="less">
.order {
  background: #f4f4f8;
  .recommend {
    width: 100%;
    text-align: center;
    margin: 20px 0;
    clear: both;
    img {
      display: block;
      margin: 0 auto;
      margin-bottom: 12px;
      width: 140px;
    }
    p {
      font-size: 20px;
    }
    a {
      display: inline-block;
      width: 150px;
      height: 30px;
      line-height: 30px;
      font-size: 15px;
      color: #ff464e;
      border: 1px solid currentColor;
      text-align: center;
    }
  }
  .ordercreated {
    margin-top: 10px;
    .imgcell {
      background: #fafafa;
      .title {
        position: absolute;
        top: 10px;
        left: 80px;
        margin-left: 10px;
        display: block;
        overflow: hidden; /*超出部分隐藏*/
        text-overflow: ellipsis; /* 超出部分显示省略号 */
        white-space: nowrap; /*规定段落中的文本不进行换行 */
        width: 150px; /*需要配合宽度来使用*/
      }
      .tuih {
        // display: block;
        font-size: 10px;
        color: white;
        background-color: #ff464e;
        margin-left: 10px;
      }
      .num {
        position: absolute;
        top: 20px;
        right: 0px;
        font-size: 10px;
      }
    }
    .zffs {
      img {
        width: 24px;
        height: 24px;
        margin: 0px 16px 0px 0px;
      }
      .zfm {
        font-size: 12px;
        position: relative;
        top: -6px;
      }
      .payway-tips-text {
        font-size: 8px;
        position: relative;
        top: -6px;
        color: #bbb;
      }
    }
  }
}
</style>